package com.yd.mvc.baseController.util;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;


/**
 * get方法获取手机归属地
 * @author Administrator
 *
 */
public class mobilephone {
    public static String getPhoneInfo(String mobileCode,String userID) throws Exception{
        URL url =new URL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode="+mobileCode+"&userID="+userID);
        HttpURLConnection counc = (HttpURLConnection) url.openConnection();
        counc.setRequestMethod("GET");
        String place="";
        if(counc.getResponseCode()==HttpURLConnection.HTTP_OK){
            InputStream is=counc.getInputStream();
            ByteArrayOutputStream boas=new ByteArrayOutputStream();
            byte[] buffer=new byte[1024];
            int len;
            if((len=is.read(buffer)) != -1){
                boas.write(buffer, 0, len);
            }
            place=boas.toString();
            boas.close();
            is.close();

        }
        return place;
    }
    public static void main(String[] args) throws Exception{
        mobilephone mobilephone=new mobilephone();
        System.out.print(mobilephone.getPhoneInfo("18765313125", ""));
    }

}
